<?php
/**
 * This file is part of DomAr.
 * 
 * DomAr is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * DomAr is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with DomAr.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @link http://inditel.ee/
 * @copyright 2007-2009 Inditel Meedia OÜ
 * @author Oliver Leisalu <oliver@inditel.ee>
 */


/**
* @package DomAr
* @subpackage DomArChangeLog
*/
class DomArChangeLog extends DomArPlugin {
	
	private $newChanges = array();
	
	public function addChange( DomArChangeLogItem $change) {
		$this->newChanges[] = $change;
	}
	
	public function getNewChanges() {
		return $this->newChanges;
	}
	
	public function removeAllNewChanges() {
		$this->newChanges = array();
	}
	
	public function query() {
		$query = DomArQuery::c();
		$this->prepareQuery($query);
		return $query;
	}
	
	public function dataQuery() {
		$query = DomArDataQuery::c();
		$this->prepareQuery($query);
		return $query;
	}
	
	private function prepareQuery( DomSqlQuery $query ) {
		$parent = $this->getParent();
		$query->select('t.*')
			->from( call_user_func(array($this->getProperty()->childClassName,'getDbtable')), 't' )
			->where('t.objectId = '.$parent->id.' AND t.objectClassName = \''.get_class($parent).'\'');
	}

}
?>